import { reqC1, reqC2, reqC3 } from '../api/product/attr/index'
import { defineStore } from 'pinia'
import type { responseCategory } from '@/api/product/attr/model'
import type {categoryData} from './interface/index'
// 选择式API写法
const useCategoryStore = defineStore('category', {
    state: ():categoryData => {

        return {
            // c1数据
            c1Arr: [],
            c1Id: '',
            // c2数据
            c2Arr: [],
            c2Id: '',
            // c3数据
            c3Arr: [],
            c3Id: ''
        }
    },

    actions: {
        async getC1() {
            let result: responseCategory = await reqC1()
            this.c1Arr = result

        },
        async getC2() {
            let result: responseCategory = await reqC2(this.c1Id)
            this.c2Arr = result
            // 重新选中c1时,清空c2,c3下拉框
            this.c2Id = ''
            this.c3Id = ''
            // 清空c3数据
            this.c3Arr = []
        },
        async getC3() {
            let result: responseCategory = await reqC3(this.c2Id)
            this.c3Arr = result
            //清空c3下拉框
            this.c3Id = ''
        },
    },

    getters: {}
})

//暴露
export default useCategoryStore